import React, {useRef} from 'react';
import {useNavigate} from 'react-router-dom'

const userList = ['zhangsan','lisi','wangwu']
function Login(props) {
    const userRef = useRef()
    const navigate = useNavigate()
    const login = (e)=>{
        if(e.keyCode===13){
            if(userList.includes(userRef.current.value)){
                localStorage.setItem('token',userRef.current.value)
                navigate(-1)
            }else{
                window.alert('用户不存在~')
            }
        }
    }

    return (
        <div>
            <input type='text' onKeyUp={login} ref={userRef} placeholder='请输入用户名'/>
        </div>
    );
}

export default Login;